**Presidential Election Results
cd "C:\Users\kogan.18\Box\Projects\R_Workfolder\Foodstamp Rollout\Replication Data"
use "PresidentialReplication.dta", clear

*Dummy for FSP implementation
gen rollout=time_since_rollout<0

*Separate dummies for year relative to FSP rollout
gen rollout_Pre1y=time_since_rollout<366 & time_since_rollout>-1
gen rollout_Pre2y=time_since_rollout<731 & time_since_rollout>365
gen rollout_Pre3y=time_since_rollout<1096 & time_since_rollout>730
gen rollout_P1y=time_since_rollout<0 & time_since_rollout>-366
gen rollout_P2y=time_since_rollout<-365 & time_since_rollout>-731
gen rollout_P3y=time_since_rollout<-730 & time_since_rollout>-1096
gen rollout_P4y=time_since_rollout<-1095 & time_since_rollout>-1461
gen rollout_P5y=time_since_rollout<-1460 & time_since_rollout>-1826
gen rollout_P6y=time_since_rollout<-1825 

*Generate log of votes for each party
gen log_dem=ln(Dem)
gen log_rep=ln(Rep)
gen log_total=ln(Tot_Votes)

*Log of 1960 population
gen log_pop=log(pop60)

*Months elapsed between Jan. 1961 and FSP rollout in county
gen rollout_index=(fs_year-1961)*12 + fs_month

*Third-Party Votes
gen third_party=Tot_Votes-(Dem+Rep)
*One county where third-party vote is negative
replace third_party=0 if third_party<0
gen third_party_share=(third_party)/Tot_Votes*100
gen log_third_party=log(third_party)
gen IHS_third_party=asinh(third_party)

*Increase mat size
set matsize 10999

*Set Panel
xtset fips Elect_Year

*Generate time trend variable
gen new_year=Elect_Year-1952

*Cacluate Dem Share
gen dem_share=Dem/(Dem+Rep)*100

*Label Variables
label variable rollout "FSP Implemented"
label variable fips "Counties"
label variable high_agg "High Agg. Employment (1960)"
label variable high_poverty "High Poverty (1960)"
label variable high_caseload "High Caseload"

*Gen Rollout Change Dummy
*Set Panel
xtset fips Elect_Year
gen rollout_change=.
replace rollout_change=1 if rollout==1 & l4.rollout==0
replace rollout_change=0 if  rollout==1 & l4.rollout==1
replace rollout_change=0 if  rollout==0 & l4.rollout==0

*Gen lagged DV
gen lag_dem_share=l4.dem_share

*Save file for creating Figure 3
save "ForFig3.dta", replace

*Event study model using preferred specification, with state-by-year FEs and county-specific time trends
**This generates output to create Figure 4
set more off
xtset fips Elect_Year
xtreg dem_share rollout_Pre3y rollout_Pre2y rollout_Pre1y rollout_P1y rollout_P2y rollout_P3y rollout_P4y rollout_P5y rollout_P6y i.Elect_Year i.FIPS_State##i.Elect_Year i.fips#c.new_year, fe vce(cluster fips) level(90)
estimates store m1
esttab m1 using "event_study_Preferred.csv", replace plain keep(rollout_*) cells(b(nostar fmt(3)) ci(fmt(3))) level(90)

*Set Panel
xtset fips Elect_Year

*Table 3
xtreg dem_share rollout i.Elect_Year i.FIPS_State##i.Elect_Year i.fips#c.new_year, fe vce(cluster fips)
outreg2 using Table3.tex, tex replace ctitle(Model (1)) label keep(rollout)  addtext(State-Year FE, Yes, Year FE, No, County FE, Yes, County x Linear Trend,Yes,1960 Demographis x Linear Trend,No)
xtreg dem_share rollout i.Elect_Year i.Elect_Year i.fips#c.new_year, fe vce(cluster fips)
outreg2 using Table3.tex, tex append ctitle(Model (2)) label keep(rollout)  addtext(State-Year FE, No, Year FE, Yes, County FE, Yes, County x Linear Trend,Yes,1960 Demographis x Linear Trend,No)
xtreg dem_share rollout i.Elect_Year  i.fips#c.new_year c.dem_1960_share##c.new_year c.farmlandpct60##c.new_year c.inc3k60##c.new_year c.log_pop##c.new_year c.urban60##c.new_year c.black60##c.new_year c.age560##c.new_year c.age6560##c.new_year c.employagpct60##c.new_year c.poverty60##c.new_year, fe vce(cluster fips)
outreg2 using Table3.tex, tex append ctitle(Model (3)) label keep(rollout)  addtext(State-Year FE, No, Year FE, Yes, County FE, Yes, County x Linear Trend,Yes,1960 Demographis x Linear Trend,Yes)

*Table 4
**High Poverty 
set more off
xtreg dem_share rollout##high_poverty i.FIPS_State##i.Elect_Year i.fips#c.new_year, fe vce(cluster fips)
outreg2 using Table4.tex, tex replace ctitle(Poverty) label keep(1.rollout rollout#high_poverty)  addtext(State-Year FE, Yes, County FE, Yes, County x Linear Trend,Yes)
**High Caseload
xtreg dem_share rollout##high_caseload i.Elect_Year  i.FIPS_State##i.Elect_Year i.fips#c.new_year, fe vce(cluster fips)
outreg2 using Table4.tex, tex append ctitle(Caseload) label keep(1.rollout rollout##high_caseload)  addtext(State-Year FE, Yes, County FE, Yes, County x Linear Trend,Yes)
**High Agg Employment
set more off
xtreg dem_share rollout##high_agg i.Elect_Year  i.FIPS_State##i.Elect_Year i.fips#c.new_year, fe vce(cluster fips)
outreg2 using Table4.tex, tex append ctitle(Agg. Employment) label keep(1.rollout rollout#high_agg)  addtext(State-Year FE, Yes, County FE, Yes, County x Linear Trend,Yes)

*Table 5
**Total Votes
set more off
xtreg log_total rollout i.FIPS_State##i.Elect_Year i.fips#c.new_year, fe vce(cluster fips)
outreg2 using Table5.tex, tex replace ctitle(Total Votes (Logged)) label keep(rollout)  addtext(State-Year FE, Yes, County FE, Yes, County x Linear Trend,Yes)
**Democratic Votes
set more off
xtreg log_dem rollout i.FIPS_State##i.Elect_Year i.fips#c.new_year, fe vce(cluster fips)
outreg2 using Table5.tex, tex append ctitle(Democratic Votes (Logged)) label keep(rollout)  addtext(State-Year FE, Yes, County FE, Yes, County x Linear Trend,Yes)
**Republican Votes
set more off
xtreg log_rep rollout i.FIPS_State##i.Elect_Year i.fips#c.new_year, fe vce(cluster fips)
outreg2 using Table5.tex, tex append ctitle(Republican Votes (Logged)) label keep(rollout)  addtext(State-Year FE, Yes, County FE, Yes, County x Linear Trend,Yes)

*Appendix: Predicting Rollout
xtset FIPS_State
set more off
reg rollout_index dem_share inc3k60 log_pop urban60 black60 age560 age6560 employagpct60 poverty60 if Elect_Year==1960 , vce(cluster FIPS_State)
outreg2 using TableA1.tex, tex replace ctitle(Model (1)) label   addtext(State FE, No)
xtreg rollout_index dem_share inc3k60 log_pop urban60 black60 age560 age6560 employagpct60 poverty60 if Elect_Year==1960, fe vce(cluster FIPS_State)
outreg2 using TableA1.tex, tex append ctitle(Model (2)) label  addtext(State FE,Yes)


*Appendix: Third-Party Vote
xtset fips Elect_Year
set more off
xtreg third_party_share rollout i.FIPS_State##i.Elect_Year i.fips#c.new_year, fe vce(cluster fips)
outreg2 using TableA2.tex, tex replace ctitle(Third_Party Vote Share) label keep(rollout)  addtext(State-Year FE, Yes, County FE, Yes, County x Linear Trend,Yes)
set more off
xtreg log_third_party rollout i.FIPS_State##i.Elect_Year i.fips#c.new_year, fe vce(cluster fips)
outreg2 using TableA2.tex, tex append ctitle(Third-Party Votes (Logged)) label keep(rollout)  addtext(State-Year FE, Yes, County FE, Yes, County x Linear Trend,Yes)
set more off
xtreg IHS_third_party rollout i.FIPS_State##i.Elect_Year i.fips#c.new_year, fe vce(cluster fips)
outreg2 using TableA2.tex, tex append ctitle(Third-Party Votes (IHS)) label keep(rollout)  addtext(State-Year FE, Yes, County FE, Yes, County x Linear Trend,Yes)
